package Test.Exam;

import java.util.Scanner;

/**
 * @ClassName problem_5
 * @since: 2024/3/9 19:21
 * @auth: kirito
 * @description:
 **/
public class problem_5 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            int a = sc.nextInt();
            System.out.println(f(a));
        }

    }

    private static int f(int n) {
        int[] dp = new int[n + 1];
        dp[1] = 0;
        for (int i = 2; i <= n; i++) {
            dp[i] = i;
            for (int j = 2; j * j <= i; j++) {
                if (i % j == 0) {
                    dp[i] = Math.min(dp[i], dp[j] + dp[i / j]);
                }

            }
        }
        return dp[n];
    }
}
